﻿<UserControl x:Class="Agnes.TaskManager.TaskEditorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:ext="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
             xmlns:dxsch="http://schemas.devexpress.com/winfx/2008/xaml/scheduler"
             xmlns:core="clr-namespace:Agnes.Core;assembly=Agnes.Core"
             xmlns:csla="clr-namespace:Csla.Xaml;assembly=Csla.Xaml"
             xmlns:local="clr-namespace:Agnes.TaskManager"
             xmlns:dxec="clr-namespace:DevExpress.Xpf.Editors.Controls;assembly=DevExpress.Xpf.Core.v11.2"
             xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
             xmlns:dxschint="clr-namespace:DevExpress.Xpf.Scheduler.Drawing;assembly=DevExpress.Xpf.Scheduler.v11.2"
             FontSize="13" FontFamily="SimSun"  
             mc:Ignorable="d" d:DesignHeight="355" d:DesignWidth="568">
    <UserControl.Resources>
        <core:FalseToTrueConverter x:Key="FalseToTureConvter" />
        <core:FalseToCollapsedConverter x:Key="FalseToCollapsedConvter" />
        <local:TaskStatusToAppointmentStatusConverter x:Key="StatusConvter"/>
        <local:IntToLabelConverter x:Key="LabelConvter" />
        <local:XmlToRecurrenceInfoConverter x:Key="RecurrenceConvter" />
    </UserControl.Resources>

    <Grid Margin="5"  >
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <TabControl HorizontalAlignment="Center" Background="AliceBlue" >
            <TabItem x:Name="tiBaseInfo"  Header="基本信息" Background="Transparent" >
                <Grid Margin="5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <TextBlock Grid.Row="0" Grid.Column="0" Text="主题：" HorizontalAlignment="Right" 
                               VerticalAlignment="Center" Margin="5" />
                    <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="1"  Grid.ColumnSpan="4" >
                        <dxe:TextEdit NullText="请输入主题..." 
                                      Margin="5,5"  MinWidth="400" Text="{Binding Model.Subject}"/>
                        <csla:PropertyStatus Property="{Binding Model.Subject}" />
                    </StackPanel>


                    <TextBlock Grid.Row="1" Grid.Column="0" Text="开始时间：" HorizontalAlignment="Right"
                               VerticalAlignment="Center" Margin="5"/>
                    <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1">
                        <ext:DateTimePicker Grid.Row="1" Grid.Column="1" Margin="5" MinWidth="150"
                                        Value="{Binding Model.StartDT}"
                                        Format="Custom"  FormatString="yyyy-MM-dd HH:mm"
                                        IsEnabled="{Binding ElementName=cbAllDay,Path=IsChecked,Converter={StaticResource FalseToTureConvter}}"/>
                        <csla:PropertyStatus Property="{Binding Model.StartDT}"  Margin="3,0,0,0"/>
                    </StackPanel>

                    <TextBlock Grid.Row="1" Grid.Column="2" Text="结束时间：" 
                               HorizontalAlignment="Right" Margin="5"
                               VerticalAlignment="Center" />
                    <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="3">
                        <ext:DateTimePicker Grid.Row="1" Grid.Column="3" Margin="5" MinWidth="150"
                                        Value="{Binding Model.EndDT}"
                                        Format="Custom"  FormatString="yyyy-MM-dd HH:mm"
                                        IsEnabled="{Binding ElementName=cbAllDay,Path=IsChecked,Converter={StaticResource FalseToTureConvter}}"/>
                        <csla:PropertyStatus Property="{Binding Model.EndDT}" Margin="3,0,0,0"/>
                    </StackPanel>

                    <StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1" Margin="5" >
                        <CheckBox x:Name="cbAllDay" Content="全天事件" VerticalContentAlignment="Center" Margin="15,0"
                                       VerticalAlignment="Center" 
                                       IsChecked="{Binding Model.IsAllDay}"/>
                        <csla:PropertyStatus Property="{Binding Model.IsAllDay}" Margin="5"/>
                    </StackPanel>

                    <TextBlock Grid.Row="2" Grid.Column="2" Text="完成率：" 
                               HorizontalAlignment="Right" VerticalAlignment="Center"
                               Margin="5"/>
                    <ext:IntegerUpDown Grid.Row="2" Grid.Column="3"  Margin="5" MinWidth="70"
                                       Minimum="0" Maximum="100" Value="{Binding Model.Progress, Mode=TwoWay}"
                                       HorizontalAlignment="Left"/>

                    <TextBlock Text="标签："  Grid.Row="3" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                    <dxsch:AppointmentLabelEdit Grid.Row="3" Grid.Column="1" Margin="5,5,25,5" 
                                                Storage="{Binding Path=TaskManager.SchedulerStorage}"
                                                SelectedItem="{Binding Model.LabelId,Converter={StaticResource LabelConvter},Mode=TwoWay}"
                                                />
                    <TextBlock Text="状态：" VerticalAlignment="Center" Grid.Row="3" Grid.Column="2" Margin="5" HorizontalAlignment="Right" />
                    <dxsch:AppointmentStatusEdit Grid.Row="3" Grid.Column="4" Margin="5,5,25,5"
                                                 Storage="{Binding Path=TaskManager.SchedulerStorage}"
                                                 EditMode="Standalone"
                                                 SelectedItem="{Binding Model.TaskStatus, Converter={StaticResource StatusConvter}, Mode=TwoWay}"
                                                 />
                    
                    
                    <TextBox Grid.Row="5" Grid.ColumnSpan="4" Margin="10" AcceptsReturn="True" MinHeight="100"
                             Text="{Binding Model.Description}"/>


                </Grid>
            </TabItem>
            <TabItem Header="循环选项" Width="{Binding ElementName=tiBaseInfo,Path=Width}" 
                     Height="{Binding ElementName=tiBaseInfo,Path=Height}" >
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <GroupBox Header="循环类型" Grid.Row="1" >
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0" >
                                <RadioButton x:Name="rbDaily" Click="Daily_Click" Content="每天" Margin="5,3"  />
                                <RadioButton x:Name="rbWeekly" Click="Weekly_Click" Content="每周" Margin="5,3" />
                                <RadioButton x:Name="rbMonthly" Click="Monthly_Click" Content="每月" Margin="5,3" />
                                <RadioButton x:Name="rbYearly" Click="Yealy_Click" Content="每年" Margin="5,3" />
                            </StackPanel>
                            <Path Grid.Column="1" Data="M 0,0 V 100" Fill="Black" StrokeThickness="2"/>
                            <StackPanel Grid.Column="2" Margin="10"
                                        Visibility="{Binding ElementName=rbDaily,Path=IsChecked,Converter={StaticResource FalseToCollapsedConvter}}">
                                <StackPanel Orientation="Horizontal" >
                                    <RadioButton x:Name="rbEveryDay" 
                                                 GroupName="GN1"
                                                 Content="每 " VerticalAlignment="Center" Click="rbEveryDay_Click"/>
                                    <ext:IntegerUpDown x:Name="iuPeriodicity" Margin="5" Height="23" Width="50"
                                                       IsEnabled="{Binding ElementName=rbEveryDay,Path=IsChecked}"
                                                       Value="{Binding Path=Appointment.RecurrenceInfo.Periodicity,Mode=TwoWay}" />
                                    <TextBlock Text="   天执行" VerticalAlignment="Center"/>
                                </StackPanel>
                                <RadioButton x:Name="rbWorkDay" GroupName="GN1" Content="每个工作日执行" Margin="0, 10" Click="rbWorkDay_Click"/>
                            </StackPanel>
                            <StackPanel Grid.Column="2" Margin="10"
                                        Visibility="{Binding ElementName=rbWeekly,Path=IsChecked,Converter={StaticResource FalseToCollapsedConvter}}">
                                <StackPanel Orientation="Horizontal">
                                    <ext:IntegerUpDown Margin="5" Height="23" Width="50"
                                                       Value="{Binding Path=Appointment.RecurrenceInfo.Periodicity,Mode=TwoWay}" />
                                    <TextBlock Text="   个星期循环" VerticalAlignment="Center"/>
                                </StackPanel>
                                <DockPanel>
                                    <CheckBox Margin="3" x:Name="cbMonday" Content="星期一" Click="cbMonday_Click"/>
                                    <CheckBox Margin="3" x:Name="cbTuesday" Content="星期二" Click="cbTuesDay_Click"/>
                                    <CheckBox Margin="3" x:Name="cbWednesday" Content="星期三" Click="cbWednesday_Click"/>
                                    <CheckBox Margin="3" x:Name="cbThursday" Content="星期四" Click="cbThursday_Click"/>
                                    <CheckBox Margin="3" x:Name="cbFriday" Content="星期五" Click="cbFriday_Click"/>
                                    <CheckBox Margin="3" x:Name="cbSaturday" Content="星期六" Click="cbSaturday_Click"/>
                                    <CheckBox Margin="3" x:Name="cbSunday" Content="星期天" Click="cbSunday_Click"/>
                                </DockPanel>
                            </StackPanel>
                            <StackPanel Grid.Column="2" Margin="10"
                                        Visibility="{Binding ElementName=rbMonthly,Path=IsChecked,Converter={StaticResource FalseToCollapsedConvter}}">
                                <StackPanel Orientation="Horizontal">
                                    <RadioButton GroupName="GN2" x:Name="rbNoneWeekOfMonth" Content="每 " VerticalAlignment="Center" Click="rbNoneWeekOfMonth_Click"/>
                                    <ext:IntegerUpDown Margin="5" Height="23" Width="50"
                                                       IsEnabled="{Binding ElementName=rbNoneWeekOfMonth,Path=IsChecked}"
                                                       Value="{Binding Path=Appointment.RecurrenceInfo.Periodicity,Mode=TwoWay}"/>
                                    <TextBlock Text=" 个月的 " VerticalAlignment="Center"/>
                                    <ext:IntegerUpDown Margin="5" Height="23" Width="50"
                                                       IsEnabled="{Binding ElementName=rbNoneWeekOfMonth,Path=IsChecked}"
                                                       Value="{Binding Path=Appointment.RecurrenceInfo.DayNumber,Mode=TwoWay}" />
                                    <TextBlock Text=" 号执行" VerticalAlignment="Center"/>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <RadioButton x:Name="rbWeekOfMonth" GroupName="GN2" Content="每 " Margin="0, 10"/>
                                    <ext:IntegerUpDown Margin="5" Height="23" Width="50"
                                                       Value="{Binding Path=Appointment.RecurrenceInfo.Periodicity,Mode=TwoWay}" 
                                                       IsEnabled="{Binding ElementName=rbWeekOfMonth,Path=IsChecked}"/>
                                    <TextBlock Text=" 个月的 " VerticalAlignment="Center" />
                                    <ComboBox x:Name="cbWeekOfMonth" Background="White" Margin="5" Height="23" Width="50"
                                              SelectionChanged="cbWeekOfMonth_SelectionChanged"
                                              IsEnabled="{Binding ElementName=rbWeekOfMonth,Path=IsChecked}">
                                        <ComboBoxItem Content="第一个" />
                                        <ComboBoxItem Content="第二个" />
                                        <ComboBoxItem Content="第三个" />
                                        <ComboBoxItem Content="第四个" />
                                        <ComboBoxItem Content="最后一个" />
                                    </ComboBox>
                                    <TextBlock Text=" 个星期的 " VerticalAlignment="Center" />
                                    <ComboBox x:Name="cbWeekDays" Width="80" Height="23" Background="White"
                                              IsEnabled="{Binding ElementName=rbWeekOfMonth,Path=IsChecked}"
                                              SelectionChanged="cbWeekDays_SelectionChanged">
                                        <ComboBoxItem Content="星期一" />
                                        <ComboBoxItem Content="星期二" />
                                        <ComboBoxItem Content="星期三" />
                                        <ComboBoxItem Content="星期四" />
                                        <ComboBoxItem Content="星期五" />
                                        <ComboBoxItem Content="星期六" />
                                        <ComboBoxItem Content="星期天" />
                                        <ComboBoxItem Content="工作日" />
                                        <ComboBoxItem Content="周末" />
                                        <ComboBoxItem Content="每一天" />
                                    </ComboBox>
                                    <TextBlock Text=" 执行" VerticalAlignment="Center"/>
                                </StackPanel>
                            </StackPanel>
                            <StackPanel Grid.Column="2" Margin="10"
                                        Visibility="{Binding ElementName=rbYearly,Path=IsChecked,Converter={StaticResource FalseToCollapsedConvter}}">
                                <StackPanel Orientation="Horizontal">
                                    <RadioButton GroupName="GN3" x:Name="rbNoneWeekOfMonth1" Content="" VerticalAlignment="Center" Click="rbNoneWeekOfMonth_Click"/>
                                    <ComboBox Width="80" Height="23" Background="White"
                                              SelectedIndex="{Binding Path=Appointment.RecurrenceInfo.Month,Mode=TwoWay}"
                                              IsEnabled="{Binding ElementName=rbNoneWeekOfMonth1,Path=IsChecked}">
                                        <ComboBoxItem Content="" Visibility="Collapsed"/>
                                        <ComboBoxItem Content="一月份" />
                                        <ComboBoxItem Content="二月份" />
                                        <ComboBoxItem Content="三月份" />
                                        <ComboBoxItem Content="四月份" />
                                        <ComboBoxItem Content="五月份" />
                                        <ComboBoxItem Content="六月份" />
                                        <ComboBoxItem Content="七月份" />
                                        <ComboBoxItem Content="八月份" />
                                        <ComboBoxItem Content="九月份" />
                                        <ComboBoxItem Content="十月份" />
                                        <ComboBoxItem Content="十一月份" />
                                        <ComboBoxItem Content="十二月份" />
                                    </ComboBox>
                                    <TextBlock Text="的 " VerticalAlignment="Center"/>
                                    <ext:IntegerUpDown Margin="5" Height="23" Width="50"
                                                       Value="{Binding Path=Appointment.RecurrenceInfo.DayNumber,Mode=TwoWay}"
                                                       IsEnabled="{Binding ElementName=rbNoneWeekOfMonth1,Path=IsChecked}"/>
                                    <TextBlock Text=" 号执行" VerticalAlignment="Center"/>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <RadioButton GroupName="GN3" x:Name="rbWeekOfMonth1" Content="" VerticalAlignment="Center"/>
                                    <ComboBox Width="80" Height="23" Background="White"
                                              IsEnabled="{Binding ElementName=rbWeekOfMonth1,Path=IsChecked}"
                                              SelectedIndex="{Binding Path=Appointment.RecurrenceInfo.Month,Mode=TwoWay}">
                                        <ComboBoxItem Content="" Visibility="Collapsed"/>
                                        <ComboBoxItem Content="一月份" />
                                        <ComboBoxItem Content="二月份" />
                                        <ComboBoxItem Content="三月份" />
                                        <ComboBoxItem Content="四月份" />
                                        <ComboBoxItem Content="五月份" />
                                        <ComboBoxItem Content="六月份" />
                                        <ComboBoxItem Content="七月份" />
                                        <ComboBoxItem Content="八月份" />
                                        <ComboBoxItem Content="九月份" />
                                        <ComboBoxItem Content="十月份" />
                                        <ComboBoxItem Content="十一月份" />
                                        <ComboBoxItem Content="十二月份" />
                                    </ComboBox>
                                    <TextBlock Text="的 " VerticalAlignment="Center"/>
                                    <ComboBox x:Name="cbWeekOfMonth1"
                                              Background="White" Margin="5" Height="23" Width="50"
                                              IsEnabled="{Binding ElementName=rbWeekOfMonth1,Path=IsChecked}"
                                              SelectionChanged="cbWeekOfMonth_SelectionChanged">
                                        <ComboBoxItem Content="第一个" />
                                        <ComboBoxItem Content="第二个" />
                                        <ComboBoxItem Content="第三个" />
                                        <ComboBoxItem Content="第四个" />
                                        <ComboBoxItem Content="最后一个" />
                                    </ComboBox>
                                    <TextBlock Text=" 星期的 " VerticalAlignment="Center"/>
                                    <ComboBox Width="80" Height="23" Background="White" 
                                              x:Name="cbWeekDays1"
                                              IsEnabled="{Binding ElementName=rbWeekOfMonth1,Path=IsChecked}"
                                              SelectionChanged="cbWeekDays_SelectionChanged">
                                        <ComboBoxItem Content="星期一" />
                                        <ComboBoxItem Content="星期二" />
                                        <ComboBoxItem Content="星期三" />
                                        <ComboBoxItem Content="星期四" />
                                        <ComboBoxItem Content="星期五" />
                                        <ComboBoxItem Content="星期六" />
                                        <ComboBoxItem Content="星期天" />
                                        <ComboBoxItem Content="工作日" />
                                        <ComboBoxItem Content="周末" />
                                        <ComboBoxItem Content="每一天" />
                                    </ComboBox>
                                    <TextBlock Text=" 执行" VerticalAlignment="Center" />
                                </StackPanel>
                            </StackPanel>
                        </Grid>
                    </GroupBox>
                    <GroupBox Header="结束条件" Grid.Row="2" Margin="0,3">
                        <StackPanel Margin="5">
                            <RadioButton x:Name="rbNoEndDate" GroupName="GN4" Margin="0,5" Content="不结束" Click="rbNoEndDate_Click" />
                            <StackPanel Orientation="Horizontal">
                                <RadioButton GroupName="GN4"  x:Name="rbOcurrenceCount" Click="rbOcurrenceCount_Click" Margin="0,5" VerticalAlignment="Center" Content="循环次数：" />
                                <ext:IntegerUpDown Margin="5" MinWidth="50" x:Name="iuOcurrenceCount"
                                                   IsEnabled="{Binding ElementName=rbOcurrenceCount,Path=IsChecked,Mode=TwoWay}"
                                                   Value="{Binding Path=Appointment.RecurrenceInfo.OccurrenceCount}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <RadioButton x:Name="rbEndDate" GroupName="GN4" Margin="0,5" VerticalAlignment="Center" Content="结束时间：" />
                                <ext:DateTimePicker Margin="5" MinWidth="150" x:Name="dtpEndDate"
                                                    Value="{Binding Path=Appointment.RecurrenceInfo.End}"
                                                    IsEnabled="{Binding ElementName=rbEndDate,Path=IsChecked}"/>
                            </StackPanel>
                        </StackPanel>
                    </GroupBox>
                </Grid>
            </TabItem>
            <TabItem Header="任务提醒" Width="{Binding ElementName=tiBaseInfo,Path=Width}" 
                     Height="{Binding ElementName=tiBaseInfo,Path=Height}"
                     Loaded="TabItem_Loaded">
                <StackPanel Margin="5">
                    <CheckBox Content="开始前提醒" x:Name="cbStartAlert" Click="StartAlert"/>
                </StackPanel>
            </TabItem>
        </TabControl>

        <StackPanel Grid.Row="1" Orientation="Horizontal" FlowDirection="RightToLeft">
            <Button x:Name="Cancel" Content="取消" MinWidth="80" Margin="5"/>
            <Button x:Name="Save" Content="保存" MinWidth="80" Margin="5"/>
        </StackPanel>
    </Grid>
</UserControl>
